package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysPaperConvert;
import net.learn.system.convert.SysPaperQuestionConvert;
import net.learn.system.dao.SysPaperQuestionDao;
import net.learn.system.entity.SysPaperEntity;
import net.learn.system.entity.SysPaperQuestionEntity;
import net.learn.system.query.SysPaperQuery;
import net.learn.system.query.SysPaperQuestionQuery;
import net.learn.system.service.SysPaperQuestionService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysPaperQuestionVO;
import net.learn.system.vo.SysPaperVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author 李立志
 * @since 2022-01-11
 */
@Service
public class SysPaperQuestionServiceImpl extends BaseServiceImpl<SysPaperQuestionDao, SysPaperQuestionEntity> implements SysPaperQuestionService {
    @Override
    public Boolean addPaperQuestion(SysPaperQuestionVO vo){
        SysPaperQuestionEntity entity = SysPaperQuestionConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        return baseMapper.insert(entity)>0;
    }
    @Override
    public Boolean updatePaperQuestion(SysPaperQuestionVO vo){
        SysPaperQuestionEntity entity = SysPaperQuestionConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {

        removeByIds(idList);
    }
    @Override
    public List<SysPaperQuestionVO> qryPaperQuestionList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return baseMapper.selectList(queryWrapper);
    }
    @Override
    public PageResult<SysPaperQuestionVO> qryPaperQuestionListPage(SysPaperQuestionQuery query) {
        IPage<SysPaperQuestionEntity> page = baseMapper.qryPaperQuestionListPage(getPage(query), query);

        return new PageResult<>(SysPaperQuestionConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
